<?php
/***************************************************************************
 *
 *   copyright            : (C) 2005 Winds of Storm
 *
 *   $Id: inv_fal.php,v 1.6 2007/02/11 12:23:06 nonny Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

require("db." . $phpEx);
require("load_config." . $phpEx);

$ibf_prefix             = $config['FORUM_DB_PREFIX'];
$users_table            = $ibf_prefix . "members";
$smilies_table          = $ibf_prefix . "emoticons";
$smile_pattern_field    = "typed";
$smile_url_field        = "image";
$avatars_upload_path    = $config['FORUM_BASE_URL'] . "uploads/";
$avatars_html_path      = $config['FORUM_BASE_URL'] . "html/avatars/";

function getAvatar($userinfo) {
    global  $avatars_upload_path;
    global  $avatars_html_path;

    // returns URL to the avatar to display for the user
    if ($userinfo['avatar'] != "" && $userinfo['avatar'] != "noavatar") {
        if (eregi("^upload:", $userinfo['avatar'])) {
            $avatar = eregi_replace('upload:', $avatars_upload_path, $userinfo['avatar']);
        } else if (!eregi("://", $userinfo['avatar'])) {
            $avatar = $avatars_html_path . $userinfo['avatar'];
        } else {
            $avatar = $userinfo['avatar'];
        }
        $avatar = addslashes($avatar);
    }
    return $avatar;
}

function getProfileURL($userinfo) {
    global  $config;

    $url    = $config['FORUM_BASE_URL'] . "index.$phpEx?showuser=" . $userinfo['userid'];
    return $url;
}

function checkAuth($username, $password, $modGroup, $checkAdmin) {
    // success: return user info array
    // failure: return error string
    global  $db2;

    $pw5    = md5($_REQUEST['password']);
    $sql    = "SELECT *
            FROM
                $users_table AS u
            WHERE
                name LIKE '{$_REQUEST['username']}' AND
                password='$pw5'";

        $str_sql        = ereg_replace("\t", "", $sql);
        $str_sql        = ereg_replace("\n", " ", $str_sql);
        addToLog("authLogin: Login SQL -- $str_sql");

        $result = $db2->sql_query($sql);

        if (!$result) {
                return "Error authenticating account, please try back later.";
        }

        $row    = $db2->sql_fetchrow($result);

        $userinfo['userid']     = $row['id'];
        $userinfo['username']   = $row['name'];
        $userinfo['moderator']  = 0;
        if (($row['mgroup'] == $modGroup) || ($row['user_level'] == 1)) {
                $userinfo['moderator']  = 1;
        }
        $userinfo['avatar']     = $row['avatar'];

    return  $userinfo;
}

function checkBoardBan($ip, $userid) {
    // returns boolean result
    return  FALSE;
}

function checkValidAlias($alias, $uid) {
    // returns boolean result
    return  TRUE;
}

